package vip.xiaonuo.smzq.modular.kcl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import oshi.driver.mac.net.NetStat;
import vip.xiaonuo.common.page.CommonPageRequest;
import vip.xiaonuo.smzq.core.tools.UniversalTool;
import vip.xiaonuo.smzq.modular.deom.TypeProcessing;
import vip.xiaonuo.smzq.modular.dictionary.entity.*;
import vip.xiaonuo.smzq.modular.dictionary.mapper.*;
import vip.xiaonuo.smzq.modular.hisi.entity.vo.KcdgmtjVo;
import vip.xiaonuo.smzq.modular.kcl.entity.*;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.Kszlzb;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.ReserveData;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.ReservesEdit;
import vip.xiaonuo.smzq.modular.kcl.entity.vo.ResourceReserves;
import vip.xiaonuo.smzq.modular.kcl.mapper.*;
import vip.xiaonuo.smzq.modular.kcl.service.IZyclService;
import vip.xiaonuo.smzq.modular.lifecycle.entity.LifeCycleMineralMea;
import vip.xiaonuo.smzq.modular.lifecycle.po.PAFPushPO;
import vip.xiaonuo.smzq.modular.lifecycle.service.ExtCallService;
import vip.xiaonuo.smzq.modular.psba.entity.*;
import vip.xiaonuo.smzq.modular.psba.mapper.*;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 资源储量 服务实现类
 *
 * @author eomer
 * @since 2024-02-22
 */
@Service
public class ZyclServiceImpl extends ServiceImpl<ZyclMapper, Zycl> implements IZyclService {

    @Resource
    private ZyclMapper zyclMapper;
    @Resource
    private Cb13ZycllxMapper cb13ZycllxMapper;//资源储量类型
    @Resource
    private KczycllzbmdybMapper kczycllzbmdybMapper; //矿产资源储量总量类型编码对应表
    @Resource
    private Cb06KcMapper cb06KcMapper; //矿产
    @Resource
    private Cb03KspjMapper cb03KspjMapper;//矿石品级
    @Resource
    private Cb02KslxMapper cb02KslxMapper;//矿石类型
    @Resource
    private ZlMapper zlMapper;//矿石质量
    @Resource
    private BgMapper bgMapper;//报告
    @Resource
    private Cb01ZhMapper cb01ZhMapper;//字典综合
    @Resource
    private KsMapper ksMapper;//矿山基本信息
    @Resource
    private ZbMapper zbMapper;//矿山坐标


    //非压覆基本情况
    @Resource
    private PsbaSqjlJbqkMapper psbaSqjlJbqkMapper;
    //压覆基本情况
    @Resource
    private PsbaSqjlYfjbqkMapper psbaSqjlYfjbqkMapper;

    //评审备案资源储量
    @Resource
    private PsbaGtZyclMapper psbaGtZyclMapper;
    //评审备案报告
    @Resource
    private PsbaGtBgMapper psbaGtBgMapper;

    @Resource
    private ExtCallService extCallService;
    @Resource
    private PsbaGtZlMapper psbaGtZlMapper;//质量
    @Resource
    private PsbaGtZbMapper psbaGtZbMapper;//坐标


    @Override
    public Page<Zycl> page(Zycl zycl) {
        QueryWrapper<Zycl> queryWrapper = new QueryWrapper<>();
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    /**
     * 资源储量列表查询
     *
     * @Param kqbm 矿区编码
     * @Param djflbm 登记分类编码
     * @Param nd 年度
     */
    @Override
    public List<ResourceReserves> getResourceReservesList(String kqbm, Integer djflbm, Integer nd) {
        //返回的资源储量列表
        List<ResourceReserves> returnZyclList = new ArrayList<>();
        try {
            //1.查询一共当前矿当前年度存在多少矿石类型 进行遍历分组
            List<Integer> kslxList = new ArrayList<>();
            if (djflbm != null) {
                kslxList = zyclMapper.getKslxList(kqbm, djflbm, nd);
            } else {
                kslxList = zyclMapper.getKslxListNoDjflbm(kqbm, nd);
            }

            List<List<Zycl>> groupZyclList = new ArrayList<>();
            for (Integer kslx : kslxList) {
                //3.1.查询当前类型下的数据
                QueryWrapper<Zycl> queryWrapper1 = new QueryWrapper<>();
                queryWrapper1.eq("kqbh", kqbm);
                if (djflbm != null) {
                    queryWrapper1.eq("djflbh", djflbm);
                }
                queryWrapper1.eq("nd", nd);
                queryWrapper1.eq("kslx", kslx);
                //  queryWrapper1.eq("zycllx", kslx);

                List<Zycl> zyclList2 = zyclMapper.selectList(queryWrapper1);
                groupZyclList.add(zyclList2);
            }
            //2.将每组的数据根据储量类型进行分组并计算对应值
            List<Cb13Zycllx> cb13List = cb13ZycllxMapper.selectList(new QueryWrapper<>());

            //包含代码类型的矿产质量
            List<ResourceReserves> returnZyclList2 = new ArrayList<>();
            for (List<Zycl> zyclList : groupZyclList) {
                //同一个矿石类型数据
                //根据不同的存储类型进行分组
                for (Cb13Zycllx cb13 : cb13List) {
                    //定义根据存储类型进行分组
                    List<Zycl> storageGroup = new ArrayList<>();
                    for (Zycl zycl : zyclList) {
                        if (cb13.getDm().equals(zycl.getZycllx())) {
                            storageGroup.add(zycl);
                        }
                    }
                    ResourceReserves resourceReserves = getResourceReserves(storageGroup);
                    //情况一：目前没有出现重复类型的数据
                    if (resourceReserves != null && resourceReserves.getKcmc() != null) {
                        returnZyclList2.add(resourceReserves);
                    }
                }
            }
            //2.查询当前矿当前年度的矿石类型
            List<Integer> list = new ArrayList<>();
            if (djflbm != null) {
                list = zlMapper.getZllxList(kqbm, djflbm, nd);
            } else {
                list = zlMapper.getZllxListNoDjflbm(kqbm, nd);
            }

            //需要计算的矿石类型
            List<ResourceReserves> resourceList = new ArrayList<>();
            for (Integer kszl : list) {
                if (!kslxList.contains(kszl)) {
                    QueryWrapper<Zl> queryZl = new QueryWrapper<>();
                    queryZl.eq("kqbh", kqbm);
                    if (djflbm != null) {
                        queryZl.eq("djflbh", djflbm);
                    }
                    queryZl.eq("nd", nd);
                    queryZl.eq("kslx", String.valueOf(kszl));
                    List<Zl> zlList = zlMapper.selectList(queryZl);
                    for (Zl zl : zlList) {
                        List<ResourceReserves> resourceReserves = getNoResourceReserves(returnZyclList2, zl, cb13List);
                        //情况一：目前没有出现重复类型的数据
                        if (resourceReserves != null && resourceReserves.size() > 0) {
                            resourceList.addAll(resourceReserves);
                            //returnZyclList.addAll(resourceReserves);
                        }
                    }


                    //    Zl zl = zlMapper.selectOne(queryZl);


                }

            }
            if (resourceList.size() > 0) {
                returnZyclList.addAll(resourceList);

            }
            if (returnZyclList2.size() > 0) {
                returnZyclList.addAll(returnZyclList2);
            }


        } catch (Exception e) {
            System.out.println("报错报错：" + e);
        }
        return returnZyclList;
    }

    //矿石工业类型及品级(牌号)字典表未存在时需要把所有的品级进行总和计算
    public List<ResourceReserves> getNoResourceReserves(List<ResourceReserves> returnZyclList, Zl zlNotContain, List<Cb13Zycllx> cb13List) {

        List<ResourceReserves> returnList = new ArrayList<>();
        //根据不同的存储类型进行分组
        for (Cb13Zycllx cb13 : cb13List) {
            //定义根据存储类型进行分组
            List<ResourceReserves> storageGroup = new ArrayList<>();
            for (ResourceReserves reserves : returnZyclList) {
                if (cb13.getDm().equals(reserves.getLxbm())) {
                    storageGroup.add(reserves);
                }
            }
            if (storageGroup.size() == 0) {
                continue;
            }


            ResourceReserves returnZycl = storageGroup.get(0);
            //年初保有 金属量
            Double ncbyJsl = 0.0;
            //年初累计 金属量
            Double ncljJsl = 0.0;
            //开采量 金属量
            Double kclJsl = 0.0;
            //损失量 金属量
            Double sslJsl = 0.0;
            //勘察增减（±） 金属量
            Double kczjJsl = 0.0;
            //重算增减（±）金属量
            Double cszjJsl = 0.0;
            //年末保有 金属量
            Double nmbyJsl = 0.0;
            //累计查明 金属量
            Double ljcmJsl = 0.0;
            //审批压覆量 金属量
            Double spyflJsl = 0.0;
            //其他 金属量
            Double otherDataJsl = 0.0;

            //年初保有 矿石量
            Double ncbyKsl = 0.0;
            //年初累计 矿石量
            Double ncljKsl = 0.0;
            //开采量 矿石量
            Double kclKsl = 0.0;
            //损失量 矿石量
            Double sslKsl = 0.0;
            //勘察增减（±） 矿石量
            Double kczjKsl = 0.0;
            //重算增减（±）矿石量
            Double cszjKsl = 0.0;
            //年末保有 矿石量
            Double nmbyKsl = 0.0;
            //累计查明 矿石量
            Double ljcmKsl = 0.0;
            //审批压覆量 矿石量
            Double spyflKsl = 0.0;
            //其他 矿石量
            Double otherDataKsl = 0.0;
            //不包含代码类型的矿产质量
            ResourceReserves resourceReservesNew = new ResourceReserves();


            for (ResourceReserves resourceReserves : storageGroup) {

                if (resourceReserves.getNcbyJsl() != null) {
                    //年初累计 金属量
                    ncbyJsl = ncbyJsl + resourceReserves.getNcbyJsl();
                }
                if (resourceReserves.getKclJsl() != null) {
                    //开采量 金属量
                    kclJsl = kclJsl + resourceReserves.getKclJsl();
                }

                if (resourceReserves.getSslJsl() != null) {
                    //损失量 金属量
                    sslJsl = sslJsl + resourceReserves.getSslJsl();
                }
                if (resourceReserves.getKclJsl() != null) {
                    //勘察增减（±） 金属量
                    kczjJsl = kczjJsl + resourceReserves.getKclJsl();
                }
                if (resourceReserves.getCszjJsl() != null) {
                    //重算增减（±）金属量
                    cszjJsl = cszjJsl + resourceReserves.getCszjJsl();
                }
                if (resourceReserves.getNmbyJsl() != null) {
                    //年末保有 金属量
                    nmbyJsl = nmbyJsl + resourceReserves.getNmbyJsl();
                }
                if (resourceReserves.getLjcmJsl() != null) {
                    //累计查明 金属量
                    ljcmJsl = ljcmJsl + resourceReserves.getLjcmJsl();
                }
                if (resourceReserves.getSpyflJsl() != null) {
                    //审批压覆量 金属量
                    spyflJsl = spyflJsl + resourceReserves.getSpyflJsl();
                }
                if (resourceReserves.getOtherDataJsl() != null) {
                    //其他 金属量
                    otherDataJsl = +resourceReserves.getOtherDataJsl();
                }

                if (resourceReserves.getNcbyKsl() != null) {
                    //年初保有 矿石量
                    ncbyKsl = ncbyKsl + resourceReserves.getNcbyKsl();
                }

                if (resourceReserves.getNcljKsl() != null) {
                    //年初累计 矿石量
                    ncljKsl = ncljKsl + resourceReserves.getNcljKsl();
                }
                if (resourceReserves.getKclKsl() != null) {
                    //开采量 矿石量
                    kclKsl = kclKsl + resourceReserves.getKclKsl();
                }
                if (resourceReserves.getSslKsl() != null) {
                    //损失量 矿石量
                    sslKsl = sslKsl + resourceReserves.getSslKsl();
                }

                if (resourceReserves.getKczjKsl() != null) {
                    //勘察增减（±） 矿石量
                    kczjKsl = kczjKsl + resourceReserves.getKczjKsl();
                }
                if (resourceReserves.getCszjKsl() != null) {
                    //重算增减（±）矿石量
                    cszjKsl = cszjKsl + resourceReserves.getCszjKsl();
                }
                if (resourceReserves.getNmbyKsl() != null) {
                    //年末保有 矿石量
                    nmbyKsl = nmbyKsl + resourceReserves.getNmbyKsl();
                }
                if (resourceReserves.getLjcmKsl() != null) {
                    //累计查明 矿石量
                    ljcmKsl = ljcmKsl + resourceReserves.getLjcmKsl();
                }
                if (resourceReserves.getSpyflKsl() != null) {
                    //审批压覆量 矿石量
                    spyflKsl = spyflKsl + resourceReserves.getSpyflKsl();
                }
                if (resourceReserves.getOtherDataKsl() != null) {
                    //其他 矿石量
                    otherDataKsl = otherDataKsl + resourceReserves.getOtherDataKsl();
                }

            }
            //上年年末保有
            resourceReservesNew.setNmbyJsl(nmbyJsl);
            resourceReservesNew.setNmbyKsl(nmbyKsl);
            //开采量
            resourceReservesNew.setKclJsl(kclJsl);
            resourceReservesNew.setKclKsl(kclKsl);
            //损失量
            resourceReservesNew.setSslJsl(sslJsl);
            resourceReservesNew.setSslKsl(sslKsl);
            //勘察增减
            resourceReservesNew.setKczjJsl(kczjJsl);
            resourceReservesNew.setKczjKsl(kczjKsl);

            // 重算增减
            resourceReservesNew.setCszjJsl(cszjJsl);
            resourceReservesNew.setCszjKsl(cszjKsl);
            //审批压覆量
            resourceReservesNew.setSpyflJsl(spyflJsl);
            resourceReservesNew.setSpyflKsl(spyflKsl);
            //其他
            resourceReservesNew.setOtherDataJsl(otherDataJsl);
            resourceReservesNew.setOtherDataKsl(otherDataKsl);
            //年初保有
            resourceReservesNew.setNcbyJsl(ncbyJsl);
            resourceReservesNew.setNcbyKsl(ncbyKsl);

            //年初累计
            resourceReservesNew.setNcljJsl(ncljJsl);
            resourceReservesNew.setNcljKsl(ncljKsl);
            //累计查明
            resourceReservesNew.setLjcmJsl(ljcmJsl);
            resourceReservesNew.setLjcmKsl(ljcmKsl);

            //矿产名称
            returnZyclList.get(0).setKcmc(returnZycl.getKcmc());
            QueryWrapper<Cb06Kc> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("kcdm", returnZycl.getKcbm());
            queryWrapper.last("limit 1");
            Cb06Kc cb06Kc = cb06KcMapper.selectOne(queryWrapper);
            //矿产名称
            resourceReservesNew.setKcmc(cb06Kc.getKcmc());
            resourceReservesNew.setKcbm(returnZycl.getKcbm());
            if (cb06Kc.getJsldw() != null) {
                //金属量单位
                resourceReservesNew.setJsldw(cb06Kc.getJsldw());
            }
            //矿石量单位
            resourceReservesNew.setKsldw(cb06Kc.getKsldw());

            //矿产组合
            resourceReservesNew.setKczh(returnZycl.getKczh());

            //统计对象及资源储量单位
            resourceReservesNew.setTjdx(returnZycl.getTjdx());

            //矿石工业类型及品级
            resourceReservesNew.setKslx(zlNotContain.getKslx());
            resourceReservesNew.setKslxDm(Integer.valueOf(zlNotContain.getKslx()));
            resourceReservesNew.setKspj(zlNotContain.getKspj());
            resourceReservesNew.setKspjDm(zlNotContain.getKspj());

//            //矿石主要成分及质量指标
            List<Kszlzb> kszlzbs = new ArrayList<>();
            Kszlzb kszlzb = new Kszlzb();
            kszlzb.setZfz(zlNotContain.getZfz());
            kszlzb.setZfdw(zlNotContain.getZfdw());
            kszlzb.setZfm(zlNotContain.getZfm());
            kszlzbs.add(kszlzb);
            resourceReservesNew.setKszlzbs(kszlzbs);


            //类型编码
            resourceReservesNew.setLxmc(returnZycl.getLxmc());
            resourceReservesNew.setLxbm(returnZycl.getLxbm());

            returnList.add(resourceReservesNew);
        }


        return returnList;
    }


    /**
     * 同矿年度下拉框
     *
     * @Param kqbm 矿区编码
     * @Param djflbm 登记分类编码
     */
    @Override
    public List<Integer> getNdList(String kqbm, Integer djflbm) {
        return zyclMapper.getNdList(kqbm, djflbm);
    }

    /**
     * 批量添加资源储量
     */
    @Override
    public Integer addList(List<Zycl> zycls) {
        Integer count = 0;
        try {
            for (Zycl zycl : zycls) {
                count = count + zyclMapper.insert(zycl);

            }
        } catch (Exception e) {
            System.out.println(e);
        }


        return count;
    }

    /**
     * 资源储量填报编辑列表查询
     *
     * @Param kqbm 矿区编码
     * @Param djflbm 登记分类编码
     * @Param nd 年度
     */
    @Override
    public List<ReservesEdit> getReservesEditList(String kqbm, Integer djflbm, Integer nd) {
        List<ReservesEdit> returnReservesEditList = new ArrayList<>();
        try {
            List<String> strList = zlMapper.getList(kqbm, djflbm, nd);
            Zycl zycl = new Zycl();
            for (String str : strList) {
                ReservesEdit reservesEdit = new ReservesEdit();
                //矿石类型 编码
                String kslxBm = str.substring(0, str.indexOf("*"));
                //矿石品级 编码
                String kspjBm = str.substring(str.indexOf("*") + 1);

                //3.1.查询当前类型下的数据
                QueryWrapper<Zycl> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("kqbh", kqbm);
                queryWrapper.eq("djflbh", djflbm);
                queryWrapper.eq("nd", nd);
                queryWrapper.eq("kslx", Integer.valueOf(kslxBm));
                queryWrapper.eq("kspj", Integer.valueOf(kspjBm));
                List<Zycl> zyclList = zyclMapper.selectList(queryWrapper);
                if (zyclList != null && zyclList.size() > 0) {
                    zycl = zyclList.get(0);
                }
                //矿产组合
                reservesEdit.setKczh(zycl.getKczh());

                reservesEdit.setKqbh(kqbm);
                //登记分类编码
                reservesEdit.setDjflbm(djflbm);
                //年度
                reservesEdit.setNd(nd);

//                QueryWrapper<Cb06Kc> queryWrapperdw = new QueryWrapper<>();
//                queryWrapperdw.eq("kcdm", zycl.getKcdm());
//                queryWrapperdw.eq("tjdx", zycl.getTjdx());
//                Cb06Kc cb06Kc1 = cb06KcMapper.selectOne(queryWrapperdw);
//                if (cb06Kc1!=null){
//                    if (cb06Kc1.getJsldw()!=null){
//                        //金属量单位
//                        reservesEdit.setJsldw(cb06Kc1.getJsldw());
//                    }
//                    //矿石量单位
//                    reservesEdit.setKsldw(cb06Kc1.getKsldw());
//                }


                //矿石主要成分及质量指标
                QueryWrapper<Zl> queryZl = new QueryWrapper<>();
                queryZl.eq("kqbh", kqbm);
                queryZl.eq("nd", nd);
                queryZl.eq("djflbh", djflbm);
                queryZl.eq("kspj", kspjBm);
                queryZl.eq("kslx", kslxBm);
                List<Zl> zlList = zlMapper.selectList(queryZl);
                if (zlList != null && zlList.size() > 0) {
                    //矿石主要成分及质量指标
                    List<Kszlzb> kszlzbs = new ArrayList<>();
                    for (Zl zl : zlList) {
                        Kszlzb kszlzb = new Kszlzb();
                        kszlzb.setZfz(zl.getZfz());
                        kszlzb.setZfdw(zl.getZfdw());
                        kszlzb.setZfm(zl.getZfm());
                        kszlzbs.add(kszlzb);
                    }
                    reservesEdit.setKszlzbs(kszlzbs);
                    Zl zl = zlList.get(0);
                    QueryWrapper<Cb06Kc> queryWrapperCb06 = new QueryWrapper<>();
                    queryWrapperCb06.eq("kcdm", zl.getKcdm());
                    if (zl.getTjdx() != null) {
                        queryWrapperCb06.eq("tjdx", zl.getTjdx());
                    }
                    Cb06Kc cb06Kc = cb06KcMapper.selectOne(queryWrapperCb06);
                    String kcdm="";
                    if (cb06Kc != null) {
                        if (cb06Kc.getJsldw() != null&&!cb06Kc.getJsldw().equals("")) {
                            //金属量单位
                            reservesEdit.setJsldw(cb06Kc.getJsldw());
                            kcdm="3_"+cb06Kc.getKcdm()+"_"+cb06Kc.getTjdx();
                        }else{
                            kcdm="2_"+cb06Kc.getKcdm()+"_"+cb06Kc.getTjdx();
                        }
                        //矿石量单位
                        reservesEdit.setKsldw(cb06Kc.getKsldw());
                        //矿产名称
                        reservesEdit.setKcmc(cb06Kc.getKcmc());
                        //统计对象及资源储量单位
                        reservesEdit.setTjdx(cb06Kc.getKsldw());
                    }


                    reservesEdit.setKcbm(kcdm);

                    reservesEdit.setKslxDm(Integer.valueOf(zl.getKslx()));

                    reservesEdit.setKspjDm(Integer.valueOf(zl.getKspj()));

                    //计算均值
                    reservesEdit.setIfAverage(zl.getJzbs());


                    //矿石品级
                    QueryWrapper<Cb03Kspj> queryKspj = new QueryWrapper<>();
                    queryKspj.eq("kspj", Integer.valueOf(zl.getKspj()));
                    List<Cb03Kspj> cb03Kspj = cb03KspjMapper.selectList(queryKspj);
                    //矿石类型
                    QueryWrapper<Cb02Kslx> queryKslx = new QueryWrapper<>();
                    queryKslx.eq("kslx", Integer.valueOf(zl.getKslx()));
                    List<Cb02Kslx> cb02Kslx = cb02KslxMapper.selectList(queryKslx);
                    if (cb02Kslx != null && cb02Kslx.size() >0 ){
                        //矿石工业类型及品级
                        reservesEdit.setKslx(cb02Kslx.get(0).getKslxmc());

                    }
                    if (cb03Kspj != null && cb03Kspj.size()>0) {
                        reservesEdit.setKspj(cb03Kspj.get(0).getKspjmc());

                    }
                }

                List<ReserveData> reserveDatas = new ArrayList<>();
                //2.将每组的数据根据储量类型进行分组并计算对应值
                List<Cb13Zycllx> cb13List = cb13ZycllxMapper.selectList(new QueryWrapper<>());
                //同一个矿石类型数据
                //根据不同的存储类型进行分组

                for (Cb13Zycllx cb13 : cb13List) {
                    //定义根据存储类型进行分组
                    List<Zycl> storageGroup = new ArrayList<>();
                    for (Zycl zycl1 : zyclList) {
                        if (cb13.getDm().equals(zycl1.getZycllx())) {
                            storageGroup.add(zycl1);
                        }
                    }
                    if (storageGroup.size() > 0) {

                        ReserveData reserveData = getReservesEdit(storageGroup);
                        reserveDatas.add(reserveData);
                    }

                }
                reservesEdit.setReserveDatas(reserveDatas);
                returnReservesEditList.add(reservesEdit);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnReservesEditList;
    }


    /**
     * 添加资源储量及其相关
     */
    @Override
    public String addReserves(List<ReservesEdit> reservesList) {
        String result = "添加成功";
        try {

            for (ReservesEdit reservesEdit : reservesList) {
                //1.查询当前类型下的数据
                //矿区编号
                String kqbh = reservesEdit.getKqbh();
                //登记分类编码
                Integer djflbm = reservesEdit.getDjflbm();
                //年度
                Integer nd = reservesEdit.getNd();
                //矿产名称
                //String kcmc = reservesEdit.getKcmc();
                String kcdm_tjdx = reservesEdit.getKcbm();
                Integer kcbm =0;
                String tjdx = "0";

                List<Integer> kzbhList = TypeProcessing.strToList(kcdm_tjdx);
                if (kzbhList != null && kzbhList.size() == 3) {
                    kcbm = kzbhList.get(1);
                    tjdx = kzbhList.get(2).toString();

                }




//                if (reservesEdit.getTjdx() != null&&!reservesEdit.getTjdx().equals("")){
//                    tjdx=reservesEdit.getTjdx();
//                }

                //矿产组合
                String kczh = reservesEdit.getKczh();
                //统计对象及资源储量单位
                //String tjdx = reservesEdit.getTjdx();
                //矿石工业类型
                // String kslx = reservesEdit.getKslx();
                Integer kslxDm = reservesEdit.getKslxDm();
                //矿石品级
                // String kspj = reservesEdit.getKspj();
                Integer kspjDm = reservesEdit.getKspjDm();
                //是否平均
                Boolean ifAverage = reservesEdit.getIfAverage();
                //矿石主要成分及质量指标
                List<Kszlzb> Kszlzbs = reservesEdit.getKszlzbs();
                //资源储量数据
                List<ReserveData> reserveDatas = reservesEdit.getReserveDatas();

                //质量添加
                if (Kszlzbs != null && Kszlzbs.size() > 0) {
                    QueryWrapper<Zl> queryWrapper1 = new QueryWrapper<>();
                    queryWrapper1.eq("kqbh", kqbh);
                    queryWrapper1.eq("kcdm", kcbm);
                    queryWrapper1.eq("djflbh", djflbm);
                    queryWrapper1.eq("nd", nd);
                    queryWrapper1.eq("kslx", String.valueOf(kslxDm));
                    queryWrapper1.eq("kspj", String.valueOf(kspjDm));
                    int delCount = zlMapper.delete(queryWrapper1);

                    for (Kszlzb kszlzb : Kszlzbs) {
                        // kszlzb = JSONUtil.toBean(JSONUtil.toJsonStr(UniversalTool.checkObjectForNullFields(kszlzb)), Kszlzb.class);
                        Zl zl = new Zl();
                        zl.setDjflbh(djflbm);
                        zl.setJzbs(ifAverage);
                        zl.setKcdm(kcbm);
                        zl.setTjdx(Integer.valueOf(tjdx));
                        zl.setKqbh(kqbh);
                        zl.setKslx(String.valueOf(kslxDm));
                        zl.setKspj(String.valueOf(kspjDm));
                        zl.setNd(nd);
                        if (kszlzb.getZfm() != null && !kszlzb.getZfm().equals("")) {
                            zl.setZfz(kszlzb.getZfz());
                            zl.setZfdw(kszlzb.getZfdw());
                            zl.setZfm(kszlzb.getZfm());
                            int addCount = zlMapper.insert(zl);
                        }


                    }
                }
                //资源储量添加
                if (reserveDatas != null && reserveDatas.size() > 0) {
                    QueryWrapper<Zycl> queryWrapper1 = new QueryWrapper<>();
                    queryWrapper1.eq("kqbh", kqbh);
                    queryWrapper1.eq("kcdm", kcbm);
                    queryWrapper1.eq("djflbh", djflbm);
                    if (!tjdx.equals("")) {
                        queryWrapper1.eq("tjdx", Integer.valueOf(tjdx));
                    }
                    queryWrapper1.eq("nd", nd);
                    int count = zyclMapper.delete(queryWrapper1);
                    for (ReserveData reserveData : reserveDatas) {
                        reserveData = JSONUtil.toBean(JSONUtil.toJsonStr(UniversalTool.checkObjectForNullFields(reserveData)), ReserveData.class);
                        Zycl zycl = new Zycl();
                        zycl.setDjflbh(djflbm);
                        zycl.setKcdm(kcbm);
                        zycl.setKqbh(kqbh);
                        zycl.setKslx(kslxDm);
                        zycl.setKspj(kspjDm);
                        zycl.setNd(nd);

                        if (!tjdx.equals("")) {
                            zycl.setTjdx(Integer.valueOf(tjdx));
                        }

                        zycl.setZycllx(reserveData.getLxbm());
                        zycl.setKczh(kczh);
                        // 19001://年末保有
                        zycl.setZycllb(19001);
                        zycl.setJsl(reserveData.getNmbyJsl());
                        zycl.setKsl(reserveData.getNmbyKsl());
                        zyclMapper.insert(zycl);
                        // 19004://开采量
                        zycl.setZycllb(19004);
                        zycl.setJsl(reserveData.getKclJsl());
                        zycl.setKsl(reserveData.getKclKsl());
                        zyclMapper.insert(zycl);
                        // 19005://损失量
                        zycl.setZycllb(19005);
                        zycl.setJsl(reserveData.getSslJsl());
                        zycl.setKsl(reserveData.getSslKsl());
                        zyclMapper.insert(zycl);
                        // 19006://勘察增减
                        zycl.setZycllb(19006);
                        zycl.setJsl(reserveData.getKczjJsl());
                        zycl.setKsl(reserveData.getKczjKsl());
                        zyclMapper.insert(zycl);
                        // 19008://重算增减
                        zycl.setZycllb(19008);
                        zycl.setJsl(reserveData.getCszjJsl());
                        zycl.setKsl(reserveData.getCszjKsl());
                        zyclMapper.insert(zycl);
                        // 19009://审批压覆量
                        zycl.setZycllb(19009);
                        zycl.setJsl(reserveData.getSpyflJsl());
                        zycl.setKsl(reserveData.getSpyflKsl());
                        zyclMapper.insert(zycl);
                        // 19010://其他
                        zycl.setZycllb(19007);
                        zycl.setJsl(reserveData.getOtherDataJsl());
                        zycl.setKsl(reserveData.getOtherDataKsl());
                        zyclMapper.insert(zycl);
                        // 19012://年初保有
                        zycl.setZycllb(19012);
                        zycl.setJsl(reserveData.getNcbyJsl());
                        zycl.setKsl(reserveData.getNcbyKsl());
                        zyclMapper.insert(zycl);
                        // 19013://年初累计
                        zycl.setZycllb(19013);
                        zycl.setJsl(reserveData.getNcljJsl());
                        zycl.setKsl(reserveData.getNcljKsl());
                        zyclMapper.insert(zycl);

                        // 19002://累计查明
                        zycl.setZycllb(19002);
                        zycl.setJsl(reserveData.getLjcmJsl());
                        zycl.setKsl(reserveData.getLjcmKsl());
                        zyclMapper.insert(zycl);
                    }

                }


            }


        } catch (Exception e) {
            e.printStackTrace();
            result = "添加失败";
        }


        return result;
    }

    @Override
    public List<Zycl> selectList(QueryWrapper<Zycl> queryWrapperZycl) {
        return zyclMapper.selectList(queryWrapperZycl);
    }

    /**
     * 同步下一年的资源储量数据，下一年的年报任务生成
     * 年度 nd
     * 矿区编号 kqbh
     * 登记分类编号 djflbh
     */

    @Override
    public boolean synchronizationZyclData(String kqbh, Integer djflbh, Integer nd) {
        try {
            //资源储量
            QueryWrapper<Zycl> queryWrapperZycl = new QueryWrapper<>();
            queryWrapperZycl.eq("kqbh", kqbh);
            queryWrapperZycl.eq("djflbh", djflbh);
            queryWrapperZycl.eq("nd", nd);
            List<Zycl> zycls = zyclMapper.selectList(queryWrapperZycl);
            //避免重复数据执行删除资源储量
            QueryWrapper<Zycl> queryWrapperdel = new QueryWrapper<>();
            queryWrapperdel.eq("kqbh", kqbh);
            queryWrapperdel.eq("djflbh", djflbh);
            queryWrapperdel.eq("nd", nd + 1);
            zyclMapper.delete(queryWrapperdel);
            for (Zycl zycl : zycls) {
                zycl.setPkid(UUID.randomUUID().toString());
                if (zycl.getZycllb() == 19012 || zycl.getZycllb() == 19013) {
                    continue;
                }
                //年末保有
                else if (zycl.getZycllb() == 19001) {
                    QueryWrapper<Zycl> queryWrapperNm = new QueryWrapper<>();
                    queryWrapperNm.eq("kqbh", kqbh)
                            .eq("djflbh", djflbh)
                            .eq("nd", nd)
                            .eq("zycllb", 19012)
                            .eq("kslx", zycl.getKslx())
                            .eq("kspj", zycl.getKspj())
                            .eq("zycllx", zycl.getZycllx())
                            .eq("kczhm", zycl.getKczhm())
                            .eq("tjdx", zycl.getTjdx())
                            .eq("kcdm", zycl.getKcdm());
                    Zycl zyclby = zyclMapper.selectOne(queryWrapperNm);
                    if (zyclby != null) {
                        zyclby.setPkid(UUID.randomUUID().toString());
                        if (zycl.getJsl() != null) {
                            zyclby.setJsl(zycl.getJsl());
                        }
                        zyclby.setKsl(zycl.getKsl());
                        zyclby.setNd(nd + 1);
                        zyclMapper.insert(zyclby);
                    }
                    zycl.setNd(nd + 1);
                    zyclMapper.insert(zycl);


                }
                //累计查明
                else if (zycl.getZycllb() == 19002) {
                    QueryWrapper<Zycl> queryWrapperLj = new QueryWrapper<>();
                    queryWrapperLj.eq("kqbh", kqbh)
                            .eq("djflbh", djflbh)
                            .eq("nd", nd)
                            .eq("zycllb", 19013)
                            .eq("kslx", zycl.getKslx())
                            .eq("kspj", zycl.getKspj())
                            .eq("zycllx", zycl.getZycllx())
                            .eq("kczhm", zycl.getKczhm())
                            .eq("kcdm", zycl.getKcdm())
                            .eq("tjdx", zycl.getTjdx());
                    Zycl zycllj = zyclMapper.selectOne(queryWrapperLj);
                    if (zycllj != null) {
                        zycllj.setPkid(UUID.randomUUID().toString());
                        if (zycl.getJsl() != null) {
                            zycllj.setJsl(zycl.getJsl());
                        }
                        zycllj.setKsl(zycl.getKsl());
                        zycllj.setNd(nd + 1);
                        zyclMapper.insert(zycllj);
                    }
                    zycl.setNd(nd + 1);
                    zyclMapper.insert(zycl);


                } else {
                    zycl.setNd(nd + 1);
                    zycl.setKsl(0.0);

                    if (zycl.getJsl() != null) {
                        zycl.setJsl(0.0);
                    }
                    zyclMapper.insert(zycl);
                }


            }

            //同步质量数据
            LambdaQueryWrapper<Zl> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(Zl::getKqbh, kqbh);
            queryWrapper.eq(Zl::getDjflbh, djflbh);
            queryWrapper.eq(Zl::getNd, nd);
            List<Zl> zls = zlMapper.selectList(queryWrapper);

            //同步质量数据
            LambdaQueryWrapper<Zl> queryWrapperOld = new LambdaQueryWrapper<>();
            queryWrapperOld.eq(Zl::getKqbh, kqbh);
            queryWrapperOld.eq(Zl::getDjflbh, djflbh);
            queryWrapperOld.eq(Zl::getNd, nd+1);
            zlMapper.delete(queryWrapperOld);

            if (zls != null && zls.size() > 0) {
                for (Zl zl : zls) {
                    zl.setPkid(null);
                    zl.setNd(nd + 1);
                    zlMapper.insert(zl);
                }
            }
            return true;

        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 评审备案流程结束同步资产库 以及生命周期
     *
     * @param psbabh
     * @return
     */
    @Override
    public boolean synchronizationZycl(String psbabh, String time) {
        boolean flag = true;
        try {
            if (psbabh != null) {
                String firstChar = psbabh.substring(0, 1);
                String kqbh = "";
                Integer djflbh = 0;
                String ksbh = "";
                Integer nd = Integer.valueOf(DateUtil.format(new Date(), "YYYY"));
                String bglx = "";
                String fileId = "";
                //是否压覆
                boolean ifYf = false;
                if (firstChar.equals("1")) {
                    //如果是1则是非压覆
                    QueryWrapper<PsbaSqjlJbqk> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("psbabh", psbabh);
                    PsbaSqjlJbqk psbaSqjlJbqk = psbaSqjlJbqkMapper.selectOne(queryWrapper);

                    if (psbaSqjlJbqk != null) {
                        //矿区编号
                        if (psbaSqjlJbqk.getKqbh() != null) {
                            kqbh = psbaSqjlJbqk.getKqbh();
                        }
                        //矿山编号
                        if (psbaSqjlJbqk.getDjflbh() != null) {
                            djflbh = psbaSqjlJbqk.getDjflbh();
                        }
                        //矿山编号
                        if (psbaSqjlJbqk.getSsksbh() != null) {
                            ksbh = String.valueOf(psbaSqjlJbqk.getSsksbh());
                        }
                        if (psbaSqjlJbqk.getBglx() != null) {
                            bglx = psbaSqjlJbqk.getBglx();
                        }
                        if (psbaSqjlJbqk.getBgwj() != null) {
                            fileId = psbaSqjlJbqk.getBgwj();
                        }
                    }
                }
                if (firstChar.equals("2")) {
                    //如果是2则是压覆
                    QueryWrapper<PsbaSqjlYfjbqk> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("psbabh", psbabh);
                    PsbaSqjlYfjbqk psbaSqjlYfjbqk = psbaSqjlYfjbqkMapper.selectOne(queryWrapper);
                    if (psbaSqjlYfjbqk != null) {
                        if (psbaSqjlYfjbqk.getKqbh() != null) {
                            kqbh = psbaSqjlYfjbqk.getKqbh();
                        }

                        if (psbaSqjlYfjbqk.getDjflbh() != null) {
                            djflbh = psbaSqjlYfjbqk.getDjflbh();
                        }

                        if (psbaSqjlYfjbqk.getSsksbh() != null) {
                            ksbh = String.valueOf(psbaSqjlYfjbqk.getSsksbh());
                        }
                        if (psbaSqjlYfjbqk.getBglx() != null) {
                            bglx = psbaSqjlYfjbqk.getBglx();
                        }
                        if (psbaSqjlYfjbqk.getBgwj() != null) {
                            fileId = psbaSqjlYfjbqk.getBgwj();
                        }

                        ifYf = true;
                    }

                }

                //同步评审备案资产储量数据
                flag = synchronizationKsZyclData(kqbh, djflbh, nd, ksbh, psbabh, ifYf, bglx, fileId, time);

                //压覆需要同步其4000的数据（例：压覆的2001，若4001存在则合并更新数据，若不存在则创建压覆矿山再同步数据）
                if (ifYf) {
                    flag = synchronizationYfZyclData(kqbh, djflbh, ksbh, nd, psbabh, bglx, fileId, time);
                }
                //同步年报数据
                QueryWrapper<PsbaGtBg> queryWrapperBg = new QueryWrapper<>();
                queryWrapperBg.eq("psbabh", psbabh);
                PsbaGtBg psbaGtBg = psbaGtBgMapper.selectOne(queryWrapperBg);
                if (psbaGtBg != null) {
                    //相同评审备案编号只对应一份报告
                    LambdaQueryWrapper<Bg> queryBg = new LambdaQueryWrapper<>();
                    queryBg.eq(Bg::getPsbabh, psbaGtBg.getPsbabh());
                    bgMapper.delete(queryBg);
                    //同步到年报-报告
                    Bg bg = new Bg();
                    BeanUtil.copyProperties(psbaGtBg, bg);
                    bg.setNd(nd);
                    bg.setKqbh(kqbh);
                    bg.setDjflbh(djflbh);
                    bgMapper.insert(bg);
                }

            }


        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }

    /**
     * 压覆，非压覆申请通过后的资源量数据同步
     *
     * @param kqbh   矿区编号
     * @param djflbh 登记分类编号
     * @param nd     年度
     * @param ksbh   矿山编号
     * @param psbabh 评审备案编号
     * @param ifyf   评审备案报告类型（true是压覆类型，false是非压覆类型）
     * @return
     */
    public boolean synchronizationKsZyclData(String kqbh, Integer djflbh, Integer nd, String ksbh, String psbabh, boolean ifyf, String bglx, String fileId, String time) {
        boolean flag = true;

        try {
            //同步资源储量数据
            QueryWrapper<PsbaGtZycl> queryWrapperZycl = new QueryWrapper<>();
            queryWrapperZycl.eq("psbabh", psbabh);
            List<PsbaGtZycl> psbaGtZycls = psbaGtZyclMapper.selectList(queryWrapperZycl);
            if (psbaGtZycls.size() > 0 && !kqbh.equals("") && !djflbh.equals(0)) {
                for (PsbaGtZycl psbaGtZycl : psbaGtZycls) {
                    Zycl zycl = new Zycl();

                    //先执行查询操作，是否有数据，有的话更新，没有则新增
                    LambdaQueryWrapper<Zycl> queryZycl = new LambdaQueryWrapper<>();
                    queryZycl.eq(Zycl::getKqbh, kqbh);
                    queryZycl.eq(Zycl::getKcdm, psbaGtZycl.getKcdm());
                    queryZycl.eq(Zycl::getKslx, psbaGtZycl.getKslx());
                    queryZycl.eq(Zycl::getKspj, psbaGtZycl.getKspj());
                    queryZycl.eq(Zycl::getKczh, psbaGtZycl.getKczh());
                    queryZycl.eq(Zycl::getTjdx, psbaGtZycl.getTjdx());
                    queryZycl.eq(Zycl::getDjflbh, djflbh);
                    queryZycl.eq(Zycl::getZycllb, psbaGtZycl.getZycllb());
                    queryZycl.eq(Zycl::getZycllx, psbaGtZycl.getZycllx());
                    queryZycl.eq(Zycl::getNd, nd);
                    Zycl oldZycl = zyclMapper.selectOne(queryZycl);
                    BeanUtil.copyProperties(psbaGtZycl, zycl);
                    zycl.setNd(nd);
                    zycl.setKqbh(kqbh);
                    zycl.setDjflbh(djflbh);
                    zycl.setKsbh(ksbh);
                    //如果是压覆类型，则需要更新资源量对应量为负数
                    if (ifyf) {
                        double jsl = 0.0;
                        double ksl = 0.0;
                        double jslOld = 0.0;
                        double kslOld = 0.0;
                        if (oldZycl != null) {
                            if (oldZycl.getJsl() != null) {
                                jslOld = oldZycl.getJsl();
                            }
                            if (oldZycl.getKsl() != null) {
                                kslOld = oldZycl.getKsl();
                            }
                        }
                        if (psbaGtZycl.getJsl() != null) {
                            jsl = psbaGtZycl.getJsl();
                            zycl.setJsl(jslOld - jsl);
                        }
                        if (psbaGtZycl.getKsl() != null) {
                            ksl = psbaGtZycl.getKsl();
                            zycl.setKsl(kslOld - ksl);
                        }
                    }
                    if (oldZycl != null) {
                        zyclMapper.update(zycl, queryZycl);
                    } else {
                        zyclMapper.insert(zycl);
                    }
                }
            } else {
                return false;
            }

            // 同步质量数据
            flag = synchronizationZlSmzq(kqbh, djflbh, psbabh, nd);
            //同步生命周期数据
            flag = synchronizationSmzq(kqbh, djflbh, bglx, fileId, time,psbabh);

        } catch (Exception e) {
            flag = false;
            e.printStackTrace();
        }
        return flag;
    }


    /**
     * 同步质量数据
     *
     * @Param kqbh 矿区编号
     * @Param djflbh 登记分类编号
     * @Param psbabh 评审备案编号
     * @Param nd 年度
     */
    public boolean synchronizationZlSmzq(String kqbh, Integer djflbh, String psbabh, Integer nd) {
        boolean flag = true;

        try {
            LambdaQueryWrapper<PsbaGtZl> queryWrapperPsbaZl = new LambdaQueryWrapper<>();
            queryWrapperPsbaZl.eq(PsbaGtZl::getPsbabh, psbabh);
            List<PsbaGtZl> psbaGtZls = psbaGtZlMapper.selectList(queryWrapperPsbaZl);
            if (psbaGtZls != null && psbaGtZls.size() > 0) {
                for (PsbaGtZl psbaGtZl : psbaGtZls) {
                    LambdaQueryWrapper<Zl> queryWrapper = new LambdaQueryWrapper<>();
                    queryWrapper.eq(Zl::getKqbh, kqbh);
                    queryWrapper.eq(Zl::getDjflbh, djflbh);
                    queryWrapper.eq(Zl::getNd, nd);
                    queryWrapper.eq(Zl::getKcdm, psbaGtZl.getKcdm());
                    queryWrapper.eq(Zl::getTjdx, psbaGtZl.getTjdx());
                    queryWrapper.eq(Zl::getKslx, psbaGtZl.getKslx());
                    queryWrapper.eq(Zl::getKspj, psbaGtZl.getKspj());
                    queryWrapper.eq(Zl::getJzbs, psbaGtZl.getJzbs());
                    if (psbaGtZl.getZfm() != null && !psbaGtZl.getZfm().equals("")) {
                        queryWrapper.eq(Zl::getZfm, psbaGtZl.getZfm());
                        queryWrapper.eq(Zl::getZfz, psbaGtZl.getZfz());
                        queryWrapper.eq(Zl::getZfdw, psbaGtZl.getZfdw());
                        Zl zl = zlMapper.selectOne(queryWrapper);
                        if (zl == null) {
                            Zl newZl = new Zl();
                            BeanUtil.copyProperties(psbaGtZl, newZl);
                            newZl.setNd(nd);
                            newZl.setKqbh(kqbh);
                            newZl.setDjflbh(djflbh);
                            zlMapper.insert(newZl);
                        }
                    }
                }

            }
        } catch (Exception e) {
            flag = false;
            e.printStackTrace();

        }
        return flag;
    }

    /**
     * 同步坐标数据
     *
     * @Param kqbh 矿区编号
     * @Param djflbh 登记分类编号
     * @Param psbabh 评审备案编号
     * @Param nd 年度
     */
    public boolean synchronizatZbSmzq(String kqbh, Integer djflbh, String psbabh, Integer nd) {
        boolean flag = true;
        try {
            LambdaQueryWrapper<PsbaGtZb> queryWrapperPsbaZb = new LambdaQueryWrapper<>();
            queryWrapperPsbaZb.eq(PsbaGtZb::getPsbabh, psbabh);
            PsbaGtZb psbaGtZb = psbaGtZbMapper.selectOne(queryWrapperPsbaZb);
            LambdaQueryWrapper<Zb> queryWrapperZb = new LambdaQueryWrapper<>();
            queryWrapperZb.eq(Zb::getKqbh, kqbh);
            queryWrapperZb.eq(Zb::getDjflbh, djflbh);
            queryWrapperZb.eq(Zb::getNd, nd);
            Zb zb = zbMapper.selectOne(queryWrapperZb);
            Zb newZb = new Zb();
            newZb.setDjflbh(djflbh);
            newZb.setKqbh(kqbh);
            newZb.setNd(nd);
            if (psbaGtZb != null) {
                if (zb == null) {
                    if (psbaGtZb.getJszb() != null) {
                        newZb.setJszb(psbaGtZb.getJszb());
                    }
                    if (psbaGtZb.getXmfwzb() != null) {
                        newZb.setKqzb(psbaGtZb.getXmfwzb());
                    }
                    zbMapper.insert(newZb);

                } else {
                    BeanUtils.copyProperties(newZb, zb);
                    if (psbaGtZb.getJszb() != null) {
                        newZb.setJszb(psbaGtZb.getJszb());
                    }
                    if (psbaGtZb.getXmfwzb() != null) {
                        newZb.setKqzb(psbaGtZb.getXmfwzb());
                    }

                    zbMapper.updateById(newZb);
                }
            }
        } catch (Exception e) {
            flag = false;
            e.printStackTrace();
        }
        return flag;
    }


    /**
     * 新建压覆矿山 登记分类编号为4000
     */
    public boolean synchronizationYfZyclData(String kqbh, Integer djflbh, String ksbh, Integer nd, String psbabh, String bglx, String fileId, String time) {
        boolean flag = true;
        if (djflbh == null) {
            return false;
        }
        //获取余数
        int remainder = djflbh % 1000;
        //压覆登记分类编号
        int djflbhNew = 4000 + remainder;

        //查询压覆矿山是否存在
        LambdaQueryWrapper<Ks> queryWrapperKs = new LambdaQueryWrapper<>();
        queryWrapperKs.eq(Ks::getKqbh, kqbh);
        queryWrapperKs.eq(Ks::getDjflbh, djflbhNew);
        queryWrapperKs.eq(Ks::getNd, nd);
        Ks ks = ksMapper.selectOne(queryWrapperKs);
        //不存在需要创建相关信息
        if (ks == null) {
            LambdaQueryWrapper<Ks> queryWrapperOld = new LambdaQueryWrapper<>();
            queryWrapperOld.eq(Ks::getKqbh, kqbh);
            queryWrapperOld.eq(Ks::getDjflbh, djflbh);
            queryWrapperOld.eq(Ks::getNd, nd);
            Ks ksOld = ksMapper.selectOne(queryWrapperOld);

            if (ksOld != null) {
                Ks ksNew = new Ks();
                ksNew.setKqbh(kqbh);
                ksNew.setDjflbh(djflbhNew);
                ksNew.setNd(nd);
                ksNew.setKsbh(ksbh);
                if (ksOld.getKsbh() != null) {
                    ksNew.setKsbh(ksOld.getKsbh());
                }

                if (ksOld.getKsmc() != null) {
                    ksNew.setKsmc(ksOld.getKsmc());
                }

                if (ksOld.getSbbs() != null) {
                    ksNew.setSbbs(ksOld.getSbbs());
                }

                if (ksOld.getZkcm() != null) {
                    ksNew.setZkcm(ksOld.getZkcm());
                }

                if (ksOld.getTjdx() != null) {
                    ksNew.setTjdx(ksOld.getTjdx());
                }

                if (ksOld.getXzqdm() != null) {
                    ksNew.setXzqdm(ksOld.getXzqdm());
                }

                ksMapper.insert(ksNew);
            }
            //压覆，非压覆申请通过后的资源量数据同步
            synchronizationKsZyclData(kqbh, djflbhNew, nd, ksbh, psbabh, false, bglx, fileId, time);

        } else { //存在则需要与之前的数据进行更新相加

            flag = synchronizationKsZyclData(kqbh, djflbhNew, nd, psbabh, bglx, fileId, time);

        }

        //压覆同步坐标数据
        synchronizatZbSmzq(kqbh, djflbhNew,  psbabh,nd);
        return flag;
    }


    /**
     * 只同步压覆矿山的资源量数据（登记分类编号为4000+）
     *
     * @param kqbh   矿区编号
     * @param djflbh 登记分类编号
     * @param nd     年度
     * @param psbabh 评审备案编号
     * @return
     */
    public boolean synchronizationKsZyclData(String kqbh, Integer djflbh, Integer nd, String psbabh, String bglx, String fileId, String time) {
        boolean flag = true;

        try {
            //同步资源储量数据
            QueryWrapper<PsbaGtZycl> queryWrapperZycl = new QueryWrapper<>();
            queryWrapperZycl.eq("psbabh", psbabh);
            List<PsbaGtZycl> psbaGtZycls = psbaGtZyclMapper.selectList(queryWrapperZycl);
            if (psbaGtZycls.size() > 0 && !kqbh.equals("") && !djflbh.equals(0)) {
                for (PsbaGtZycl psbaGtZycl : psbaGtZycls) {
                    Zycl zycl = new Zycl();
                    if (psbaGtZycl.getJsl() == null) {
                        psbaGtZycl.setJsl(0.0);
                    }
                    if (psbaGtZycl.getKsl() == null) {
                        psbaGtZycl.setKsl(0.0);
                    }
                    //先执行查询操作，是否有数据，有的话更新，没有则新增
                    LambdaQueryWrapper<Zycl> queryZycl = new LambdaQueryWrapper<>();
                    queryZycl.eq(Zycl::getKqbh, kqbh);
                    queryZycl.eq(Zycl::getKcdm, psbaGtZycl.getKcdm());
                    queryZycl.eq(Zycl::getKslx, psbaGtZycl.getKslx());
                    queryZycl.eq(Zycl::getKspj, psbaGtZycl.getKspj());
                    queryZycl.eq(Zycl::getKczh, psbaGtZycl.getKczh());
                    queryZycl.eq(Zycl::getTjdx, psbaGtZycl.getTjdx());
                    queryZycl.eq(Zycl::getDjflbh, djflbh);
                    queryZycl.eq(Zycl::getZycllb, psbaGtZycl.getZycllb());
                    queryZycl.eq(Zycl::getZycllx, psbaGtZycl.getZycllx());
                    queryZycl.eq(Zycl::getNd, nd);
                    Zycl oldZycl = zyclMapper.selectOne(queryZycl);
                    BeanUtil.copyProperties(psbaGtZycl, zycl);
                    zycl.setNd(nd);
                    zycl.setKqbh(kqbh);
                    zycl.setDjflbh(djflbh);
                    //如果是压覆类型，则需要更新资源量对应量为负数
                    if (oldZycl != null) {
                        double jsl = 0.0;
                        double ksl = 0.0;
                        if (oldZycl.getJsl() != null) {
                            jsl = psbaGtZycl.getJsl() + oldZycl.getJsl();
                            zycl.setJsl(jsl);
                        }
                        if (oldZycl.getKsl() != null) {
                            ksl = psbaGtZycl.getKsl() + oldZycl.getKsl();
                            zycl.setKsl(ksl);
                        }
                        zyclMapper.update(zycl, queryZycl);
                    } else {
                        zyclMapper.insert(zycl);
                    }
                }
                // 同步质量数据
                flag = synchronizationZlSmzq(kqbh, djflbh, psbabh, nd);

                //同步生命周期数据
                flag = synchronizationSmzq(kqbh, djflbh, bglx, fileId, time,psbabh);
            } else {
                return false;
            }

        } catch (Exception e) {
            flag = false;
            e.printStackTrace();
        }
        return flag;
    }


    /**
     * 同步生命周期数据
     *
     * @param kqbh   矿区编号
     * @param djflbh 登记分类编号
     * @param bglx   报告类型
     * @param fileId 文件ID
     * @param time   时间
     * @return
     */
    public boolean synchronizationSmzq(String kqbh, Integer djflbh, String bglx, String fileId, String time,String psbabh) {

        boolean flag = true;

        try {
            PAFPushPO pushPO = new PAFPushPO();
            List<LifeCycleMineralMea> lifeCycleMineralMeas = new ArrayList<>();
            Integer nd = Integer.valueOf(DateUtil.format(new Date(), "YYYY"));
            pushPO.setRegClassCode(djflbh);
            pushPO.setYear(nd);
            pushPO.setMineralCode(kqbh);
            pushPO.setFileId(fileId);
            //矿业权类型：301001 无矿业权, 301002 探矿权 , 301003 采矿权
            int kqlx = djflbh / 1000;

            if (kqlx == 2) {
                pushPO.setExporeType(301003);
            } else {
                LambdaQueryWrapper<Ks> queryWrapperKs = new LambdaQueryWrapper<>();
                queryWrapperKs.eq(Ks::getKqbh, kqbh);
                queryWrapperKs.eq(Ks::getDjflbh, 1000);
                queryWrapperKs.orderByDesc(Ks::getNd);
                queryWrapperKs.last("limit 1");
                Ks ks = ksMapper.selectOne(queryWrapperKs);
                if (ks != null) {
                    if (ks.getXkzh() != null && ks.getXkzh().length() > 0) {
                        pushPO.setExporeType(301002);
                    } else {
                        pushPO.setExporeType(301001);
                    }
                }
            }
            //查询矿产代码—统计对象分组后的数据
            List<String> kcdmList = zyclMapper.getKcdmist(kqbh, djflbh, nd);


            for (String kcdm_tjdx : kcdmList) {
                List<Integer> kcdm_tjdxs = Arrays.stream(kcdm_tjdx.split(","))
                        .map(String::trim)
                        .map(Integer::parseInt)
                        .collect(Collectors.toList());
                LambdaQueryWrapper<Zycl> queryWrapper = new LambdaQueryWrapper<>();
                queryWrapper.eq(Zycl::getDjflbh, djflbh);
                queryWrapper.eq(Zycl::getKqbh, kqbh);
                queryWrapper.eq(Zycl::getNd, nd);
                queryWrapper.eq(Zycl::getZycllb, 19001);
                queryWrapper.eq(Zycl::getKcdm, kcdm_tjdxs.get(0));
                queryWrapper.eq(Zycl::getTjdx, kcdm_tjdxs.get(1));
                List<Zycl> zycls = zyclMapper.selectList(queryWrapper);

                LifeCycleMineralMea lifeCycleMineralMea = new LifeCycleMineralMea();
                lifeCycleMineralMea.setTypeStand(2);
                lifeCycleMineralMea.setMineralType(kcdm_tjdxs.get(0));
                lifeCycleMineralMea.setTjdx(kcdm_tjdxs.get(1));

                double zsKsl = 0.0;
                double kxKsl = 0.0;
                double tmKsl = 0.0;
                double tdKsl = 0.0;
                double kzKsl = 0.0;
                double qzKsl = 0.0;
                double zlKsl = 0.0;


                double zsJsl = 0.0;
                double kxJsl = 0.0;
                double tmJsl = 0.0;
                double tdJsl = 0.0;
                double kzJsl = 0.0;
                double qzJsl = 0.0;
                double zlJsl = 0.0;

                for (Zycl zycl : zycls) {

                    if (zycl.getZycllx().equals("ZS")) {
                        if (zycl.getJsl() != null) {
                            zsJsl += zycl.getJsl();
                        }
                        zsKsl += zycl.getKsl();
                    }
                    if (zycl.getZycllx().equals("KX")) {
                        if (zycl.getJsl() != null) {
                            kxJsl += zycl.getJsl();
                        }
                        kxKsl += zycl.getKsl();
                    }
                    if (zycl.getZycllx().equals("TM")) {
                        if (zycl.getJsl() != null) {
                            tmJsl += zycl.getJsl();
                        }
                        tmKsl += zycl.getKsl();
                    }
                    if (zycl.getZycllx().equals("KZ")) {
                        if (zycl.getJsl() != null) {
                            kzJsl += zycl.getJsl();
                        }
                        kzKsl += zycl.getKsl();
                    }
                    if (zycl.getZycllx().equals("TD")) {
                        if (zycl.getJsl() != null) {
                            tdJsl += zycl.getJsl();
                        }
                        tdKsl += zycl.getKsl();
                    }
                    if (zycl.getZycllx().equals("QZ")) {
                        if (zycl.getJsl() != null) {
                            qzJsl += zycl.getJsl();
                        }
                        qzKsl += zycl.getKsl();
                    }
                }


                zlKsl = tmKsl + tdKsl + kzKsl;
                zlJsl = tmJsl + tdJsl + kzJsl;
                lifeCycleMineralMea.setZs(zsKsl);
                lifeCycleMineralMea.setKx(kxKsl);
                lifeCycleMineralMea.setTm(tmKsl);
                lifeCycleMineralMea.setTd(tdKsl);
                lifeCycleMineralMea.setKz(kzKsl);
                lifeCycleMineralMea.setQz(qzKsl);
                lifeCycleMineralMea.setStoreVal(zlKsl);

                lifeCycleMineralMea.setJslZs(zsJsl);
                lifeCycleMineralMea.setJslKx(kxJsl);
                lifeCycleMineralMea.setJslTm(tmJsl);
                lifeCycleMineralMea.setJslTd(tdJsl);
                lifeCycleMineralMea.setJslKz(kzJsl);
                lifeCycleMineralMea.setJslQz(qzJsl);
                lifeCycleMineralMea.setMetalStoreVal(zlJsl);
                lifeCycleMineralMeas.add(lifeCycleMineralMea);
            }
            //储量列表
            pushPO.setLifeCycleMineralMeas(lifeCycleMineralMeas);


            if (!bglx.equals("")) {
//                pushPO.set(Integer.valueOf(bglx));
                QueryWrapper<Cb01Zh> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("dm", Integer.valueOf(bglx));
                Cb01Zh cb01Zh = cb01ZhMapper.selectOne(queryWrapper);
                pushPO.setReportName(cb01Zh.getMc());
            }

            LambdaQueryWrapper<Zb> queryWrapperZb = new LambdaQueryWrapper<>();
            queryWrapperZb.eq(Zb::getKqbh, kqbh);
            queryWrapperZb.eq(Zb::getDjflbh, djflbh);
            queryWrapperZb.eq(Zb::getNd, nd);
            queryWrapperZb.last("limit 1");
            Zb zb = zbMapper.selectOne(queryWrapperZb);
            if (zb != null) {
                //动量坐标
                if (zb.getDlzb() != null) {
                    pushPO.setMomCoor(zb.getDlzb());
                }
                //计算坐标
                if (zb.getJszb() != null) {
                    pushPO.setCalCoor(zb.getJszb());
                }
                //矿权坐标
                if (zb.getKqzb() != null) {
                    pushPO.setDmlCoor(zb.getKqzb());
                    if (djflbh>4000){
                        pushPO.setPreCovCoor(zb.getKqzb());
                    }
                }
            }
            String firstChar = psbabh.substring(0, 1);
            //压覆查询评审备案压覆坐标
            if(firstChar.equals("2")){
                LambdaQueryWrapper<PsbaGtZb> queryWrapperPsbaZb = new LambdaQueryWrapper<>();
                queryWrapperPsbaZb.eq(PsbaGtZb::getPsbabh, psbabh);
                PsbaGtZb psbaGtZb = psbaGtZbMapper.selectOne(queryWrapperPsbaZb);
                pushPO.setPreCovCoor(psbaGtZb.getXmfwzb());
            }


            pushPO.setStoreDate(Convert.convert(LocalDate.class, time));
            pushPO.setApproveStatus(1);
            extCallService.saveLcNode(pushPO);
        } catch (Exception e) {
            flag = false;
        }

        return flag;
    }


    /**
     * 每组存储类型进行算法计算
     */

    public ReserveData getReservesEdit(List<Zycl> storageGroup) {
        ReserveData reserveData = new ReserveData();
        Double ncbyJsl = 0.0;
        Double ncbyKsl = 0.0;
        Double ncljJsl = 0.0;
        Double ncljKsl = 0.0;

        if (storageGroup.size() > 0) {
            Zycl zyclGet = storageGroup.get(0);

            QueryWrapper<Zycl> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("kqbh", zyclGet.getKqbh());
            queryWrapper1.eq("djflbh", zyclGet.getDjflbh());
            queryWrapper1.eq("nd", (zyclGet.getNd() - 1));
            queryWrapper1.eq("kslx", zyclGet.getKslx());
            queryWrapper1.eq("zycllx", zyclGet.getZycllx());
            List<Zycl> zycls = zyclMapper.selectList(queryWrapper1);

            //查询上年年末
            for (Zycl zycl : zycls) {
                if (zycl.getJsl() == null) {
                    zycl.setJsl(0.0);
                }
                if (zycl.getKsl() == null) {
                    zycl.setKsl(0.0);
                }
                switch (zycl.getZycllb()) {
                    case 19001://上一年年末=当年年初保有
                        ncbyJsl = zycl.getJsl();
                        ncbyKsl = zycl.getKsl();
                        break;
                    case 19002://上一年累计查明=当年年初累计
                        ncljJsl = zycl.getJsl();
                        ncljKsl = zycl.getKsl();
                        break;
                }
            }
            if (ncljJsl > 0.0) {
                reserveData.setNcljJsl(ncljJsl);
            }
            if (ncljKsl > 0.0) {
                reserveData.setNcljKsl(ncljKsl);
            }

            if (ncbyJsl > 0.0) {
                reserveData.setNcbyJsl(ncbyJsl);
            }
            if (ncbyKsl > 0.0) {
                reserveData.setNcbyKsl(ncbyKsl);
            }


            for (Zycl zycl : storageGroup) {
                if (zycl.getJsl() == null) {
                    zycl.setJsl(0.0);
                }
                if (zycl.getKsl() == null) {
                    zycl.setKsl(0.0);
                }
                switch (zycl.getZycllb()) {
                    case 19001://上年年末保有
                        reserveData.setNmbyJsl(zycl.getJsl());
                        reserveData.setNmbyKsl(zycl.getKsl());
                        break;
                    case 19004://开采量
                        reserveData.setKclJsl(zycl.getJsl());
                        reserveData.setKclKsl(zycl.getKsl());
                        break;
                    case 19005://损失量
                        reserveData.setSslJsl(zycl.getJsl());
                        reserveData.setSslKsl(zycl.getKsl());
                        break;
                    case 19006://勘察增减
                        reserveData.setKczjJsl(zycl.getJsl());
                        reserveData.setKczjKsl(zycl.getKsl());
                        break;
                    case 19008://重算增减
                        reserveData.setCszjJsl(zycl.getJsl());
                        reserveData.setCszjKsl(zycl.getKsl());
                        break;
                    case 19009://审批压覆量
                        reserveData.setSpyflJsl(zycl.getJsl());
                        reserveData.setSpyflKsl(zycl.getKsl());
                        break;
                    case 19007://其他
                        reserveData.setOtherDataJsl(zycl.getJsl());
                        reserveData.setOtherDataKsl(zycl.getKsl());
                        break;

                    case 19012://年初保有
                        if (ncbyJsl > 0.0) {
                            reserveData.setNcbyJsl(ncbyJsl);
                        } else {
                            reserveData.setNcbyJsl(zycl.getJsl());
                        }
                        if (ncbyKsl > 0.0) {
                            reserveData.setNcbyKsl(ncbyKsl);
                        } else {
                            reserveData.setNcbyKsl(zycl.getKsl());
                        }
                        break;
                    case 19013://年初累计
                        if (ncljJsl > 0.0) {
                            reserveData.setNcljJsl(ncljJsl);
                        } else {
                            reserveData.setNcljJsl(zycl.getJsl());
                        }
                        if (ncljKsl > 0.0) {
                            reserveData.setNcljKsl(ncljKsl);
                        } else {
                            reserveData.setNcljKsl(zycl.getKsl());
                        }
                        break;

                    case 19002://累计查明
                        reserveData.setLjcmJsl(zycl.getJsl());
                        reserveData.setLjcmKsl(zycl.getKsl());
                        break;
                }
                //类型编码
                QueryWrapper<Cb13Zycllx> queryZycllx = new QueryWrapper<>();
                queryZycllx.eq("dm", zyclGet.getZycllx());
                Cb13Zycllx cb13Zycllx = cb13ZycllxMapper.selectOne(queryZycllx);
                //类型编码
                reserveData.setLxmc(cb13Zycllx.getMc());
                reserveData.setLxbm(zyclGet.getZycllx());
            }
        }

        return reserveData;
    }


    /**
     * 每组存储类型进行算法计算
     */

    public ResourceReserves getResourceReserves(List<Zycl> storageGroup) {
        ResourceReserves resourceReserves = new ResourceReserves();
        //年初保有金属量
        Double ncbyJsl = 0.0;
        //年初保有矿石量
        Double ncbyKsl = 0.0;
        //年初累计金属量
        Double ncljJsl = 0.0;
        //年初累计矿石量
        Double ncljKsl = 0.0;
        //开采量 金属量
        double kclJsl = 0;
        //损失量 金属量
        double sslJsl = 0;
        //勘察增减（±） 金属量
        double kczjJsl = 0;
        //重算增减（±）金属量
        double cszjJsl = 0;
        //年末保有 金属量
        double nmbyJsl = 0;
        //累计查明 金属量
        double ljcmJsl = 0;
        //审批压覆量 金属量
        double spyflJsl = 0;
        //其他 金属量
        double otherDataJsl = 0;
        //开采量 矿石量
        double kclKsl = 0;
        //损失量 矿石量
        double sslKsl = 0;
        //勘察增减（±） 矿石量
        double kczjKsl = 0;
        //重算增减（±）矿石量
        double cszjKsl = 0;
        //年末保有 矿石量
        double nmbyKsl = 0;
        //累计查明 矿石量
        double ljcmKsl = 0;
        //审批压覆量 矿石量
        double spyflKsl = 0;
        //其他 矿石量
        double otherDataKsl = 0;

        if (storageGroup.size() > 0) {
            Zycl zyclGet = storageGroup.get(0);


            QueryWrapper<Zycl> queryWrapper1 = new QueryWrapper<>();
            queryWrapper1.eq("kqbh", zyclGet.getKqbh());
            queryWrapper1.eq("djflbh", zyclGet.getDjflbh());
            queryWrapper1.eq("nd", (zyclGet.getNd() - 1));
            queryWrapper1.eq("kslx", zyclGet.getKslx());
            queryWrapper1.eq("zycllx", zyclGet.getZycllx());
            List<Zycl> zycls = zyclMapper.selectList(queryWrapper1);

            //查询上年年末
            for (Zycl zycl : zycls) {
                if (zycl.getJsl() == null) {
                    zycl.setJsl(0.0);
                }
                if (zycl.getKsl() == null) {
                    zycl.setKsl(0.0);
                }
                switch (zycl.getZycllb()) {
                    case 19001://上一年年末=当年年初保有
                        ncbyJsl += zycl.getJsl();
                        ncbyKsl += zycl.getKsl();
                        break;
                    case 19002://上一年累计查明=当年年初累计
                        ncljJsl += zycl.getJsl();
                        ncljKsl += zycl.getKsl();
                        break;
                }

            }

            if (ncljJsl > 0.0) {
                resourceReserves.setNcljJsl(ncljJsl);
            }
            if (ncljKsl > 0.0) {
                resourceReserves.setNcljKsl(ncljKsl);
            }

            if (ncbyJsl > 0.0) {
                resourceReserves.setNcbyJsl(ncbyJsl);
            }
            if (ncbyKsl > 0.0) {
                resourceReserves.setNcbyKsl(ncbyKsl);
            }
            for (Zycl zycl : storageGroup) {
                if (zycl.getJsl() == null) {
                    zycl.setJsl(0.0);
                }
                if (zycl.getKsl() == null) {
                    zycl.setKsl(0.0);
                }
                switch (zycl.getZycllb()) {
                    case 19001://年末保有
                        nmbyJsl += zycl.getJsl();
                        nmbyKsl += zycl.getKsl();
//                        resourceReserves.setNmbyJsl(zycl.getJsl());
//                        resourceReserves.setNmbyKsl(zycl.getKsl());
                        break;
                    case 19004://开采量
                        kclJsl += zycl.getJsl();
                        kclKsl += zycl.getKsl();
//                        resourceReserves.setKclJsl(zycl.getJsl());
//                        resourceReserves.setKclKsl(zycl.getKsl());
                        break;
                    case 19005://损失量
                        sslJsl += zycl.getJsl();
                        sslKsl += zycl.getKsl();
//                        resourceReserves.setSslJsl(zycl.getJsl());
//                        resourceReserves.setSslKsl(zycl.getKsl());
                        break;
                    case 19006://勘察增减
                        kczjJsl += zycl.getJsl();
                        kczjKsl += zycl.getKsl();
//                        resourceReserves.setKczjJsl(zycl.getJsl());
//                        resourceReserves.setKczjKsl(zycl.getKsl());
                        break;
                    case 19008://重算增减
                        cszjJsl += zycl.getJsl();
                        cszjKsl += zycl.getKsl();
//                        resourceReserves.setCszjJsl(zycl.getJsl());
//                        resourceReserves.setCszjKsl(zycl.getKsl());
                        break;
                    case 19009://审批压覆量
                        spyflJsl += zycl.getJsl();
                        spyflKsl += zycl.getKsl();
//                        resourceReserves.setSpyflJsl(zycl.getJsl());
//                        resourceReserves.setSpyflKsl(zycl.getKsl());
                        break;
                    case 19007://其他
                        otherDataJsl += zycl.getJsl();
                        otherDataKsl += zycl.getKsl();
//                        resourceReserves.setOtherDataJsl(zycl.getJsl());
//                        resourceReserves.setOtherDataKsl(zycl.getKsl());
                        break;
                    case 19012://年初保有
                        if (ncbyJsl > 0.0) {
                            resourceReserves.setNcbyJsl(ncbyJsl);
                        } else {
                            ncbyJsl += zycl.getJsl();
                            //resourceReserves.setNcbyJsl(zycl.getJsl());
                        }
                        if (ncbyKsl > 0.0) {
                            resourceReserves.setNcbyKsl(ncbyKsl);
                        } else {
                            ncbyKsl += zycl.getKsl();
//                            resourceReserves.setNcbyKsl(zycl.getKsl());
                        }
                        break;
                    case 19013://年初累计
                        if (ncljJsl == 0.0) {
                            ncljJsl += zycl.getJsl();
                        }
                        if (ncljKsl == 0.0) {
                            ncljKsl += zycl.getKsl();
                        }
                        break;
                    case 19002://累计查明
                        ljcmKsl += zycl.getKsl();
                        ljcmJsl += zycl.getJsl();
//                        resourceReserves.setLjcmJsl(zycl.getJsl());
//                        resourceReserves.setLjcmKsl(zycl.getKsl());
                        break;
                }

            }
            resourceReserves.setNmbyJsl(nmbyJsl);
            resourceReserves.setNmbyKsl(nmbyKsl);

            resourceReserves.setKclJsl(kclJsl);
            resourceReserves.setKclKsl(kclKsl);

            resourceReserves.setSslJsl(sslJsl);
            resourceReserves.setSslKsl(sslKsl);

            resourceReserves.setKczjJsl(kczjJsl);
            resourceReserves.setKczjKsl(kczjKsl);

            resourceReserves.setCszjJsl(cszjJsl);
            resourceReserves.setCszjKsl(cszjKsl);

            resourceReserves.setSpyflJsl(spyflJsl);
            resourceReserves.setSpyflKsl(spyflKsl);

            resourceReserves.setOtherDataJsl(otherDataJsl);
            resourceReserves.setOtherDataKsl(otherDataKsl);

            resourceReserves.setLjcmJsl(ljcmJsl);
            resourceReserves.setLjcmKsl(ljcmKsl);

            resourceReserves.setNcljJsl(ncljJsl);
            resourceReserves.setNcljKsl(ncljKsl);

            resourceReserves.setNcbyJsl(ncbyJsl);
            resourceReserves.setNcbyKsl(ncbyKsl);

            QueryWrapper<Cb06Kc> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("kcdm", zyclGet.getKcdm());
            queryWrapper.last("limit 1");
            Cb06Kc cb06Kc = cb06KcMapper.selectOne(queryWrapper);
            //矿产名称
            resourceReserves.setKcmc(cb06Kc.getKcmc());
            resourceReserves.setKcbm(zyclGet.getKcdm());
            if (cb06Kc.getJsldw() != null) {
                //金属量单位
                resourceReserves.setJsldw(cb06Kc.getJsldw());
            }
            //矿石量单位
            resourceReserves.setKsldw(cb06Kc.getKsldw());

            //矿产组合
            resourceReserves.setKczh(zyclGet.getKczh());

            //统计对象及资源储量单位
            resourceReserves.setTjdx(cb06Kc.getKsldw());

            //矿石品级
            QueryWrapper<Cb03Kspj> queryKspj = new QueryWrapper<>();
            queryKspj.eq("kspj", zyclGet.getKspj());
            List<Cb03Kspj> cb03Kspjs = cb03KspjMapper.selectList(queryKspj);
            Cb03Kspj cb03Kspj = cb03Kspjs.get(0);

            //矿石类型
            QueryWrapper<Cb02Kslx> queryKslx = new QueryWrapper<>();
            queryKslx.eq("kslx", zyclGet.getKslx());
            List<Cb02Kslx> cb02Kslxs = cb02KslxMapper.selectList(queryKslx);
            Cb02Kslx cb02Kslx = cb02Kslxs.get(0);
            //矿石工业类型及品级
            resourceReserves.setKslx(cb02Kslx.getKslxmc());
            resourceReserves.setKslxDm(zyclGet.getKslx());
            resourceReserves.setKspj(cb03Kspj.getKspjmc());
            resourceReserves.setKspjDm(String.valueOf(zyclGet.getKspj()));

            //矿石主要成分及质量指标
            QueryWrapper<Zl> queryZl = new QueryWrapper<>();
            queryZl.eq("kcdm", zyclGet.getKcdm());
            queryZl.eq("kqbh", zyclGet.getKqbh());
            queryZl.eq("nd", zyclGet.getNd());
            queryZl.eq("djflbh", zyclGet.getDjflbh());
            queryZl.eq("kspj", String.valueOf(zyclGet.getKspj()));
            queryZl.eq("kslx", String.valueOf(zyclGet.getKslx()));
            List<Zl> zlList = zlMapper.selectList(queryZl);
            if (zlList != null && zlList.size() > 0) {
                //矿石主要成分及质量指标
                List<Kszlzb> kszlzbs = new ArrayList<>();
                for (Zl zl : zlList) {
                    Kszlzb kszlzb = new Kszlzb();
                    kszlzb.setZfz(zl.getZfz());
                    kszlzb.setZfdw(zl.getZfdw());
                    kszlzb.setZfm(zl.getZfm());
                    kszlzbs.add(kszlzb);
                }
                resourceReserves.setKszlzbs(kszlzbs);
            }


            //类型编码
            QueryWrapper<Cb13Zycllx> queryZycllx = new QueryWrapper<>();
            queryZycllx.eq("dm", zyclGet.getZycllx());
            Cb13Zycllx cb13Zycllx = cb13ZycllxMapper.selectOne(queryZycllx);
            //类型编码
            resourceReserves.setLxmc(cb13Zycllx.getMc());
            resourceReserves.setLxbm(zyclGet.getZycllx());
        }

        return resourceReserves;
    }


}
